home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
comm
/
misc
/
atomic1_5.lha
/
atomic.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-01-03
|
9KB
|
385 lines
/* * * * * * A T O M I C . R E X X * * * * * */
/* */
/* file: s:atomic.rexx */
/* */
/* by John Chufar */
/* ver 1.5 23 Dec 1998 */
/* *Minor enhancements: */
/* -Fixes Time Difference Calculation bug */
/* -Fixes Time Zone hour offset report ( +/- offset) */
/* */
/* ************************************************************** */
startup:
/* init the command channel to AmigaDOS and see if TCP is mounted */
ADDRESS COMMAND
" Assign >NIL: TCP: exists "
IF RC = 5 THEN
DO
SAY ' TCP: not mounted ... exiting '
EXIT 10
END
startupend:
debug:
/* Use TRACE only for debug--it is very time consuming! */
/* TRACE(I) */
debugend:
titlescreen:
/* display the title screen ... */
SAY ''
SAY ' * * * A T O M I C L O C K * * * '
SAY ' Version 1.5 '
SAY ''
SAY ''
/* dst$ set module */
numargs = ARG() /* number of args */
IF numargs < 1 THEN
DO
SAY ''
SAY 'Daylight savings time? (Y or N) Then <ENTER> '
PULL dst$
END
ELSE
DO
ARG dst$
END
SAY 'Connecting to Atomic Clock server time-A.timefreq.bldrdoc.gov...'
titlescreenend:
connect:
/* open the tcp channel to the host */
IF ~OPEN(dt,'TCP:time-A.timefreq.bldrdoc.gov/daytime', 'R') THEN
DO
SAY 'Connection error with TIMESERVER - A'
SAY 'Retrying now with TIMESERVER - B'
SAY ''
SAY 'Attempting connection to time-B.timefreq.bldrdoc.gov'
IF ~OPEN(dt,'TCP:time-B.timefreq.bldrdoc.gov/daytime', 'R') THEN
DO
SAY '*** NIST Time Services are not present...exiting'
SAY ''
SAY 'Try again at a later time.'
SAY '**************************************'
EXIT 10
END
END
connectend:
decode:
/* get the atomic time from the open file 'dt' */
d = readln(dt) /* dummy read...empty first line */
d = readln(dt)
tim = SubWord(d, 3, 1)
utcdate=SubWord(d,2,1)
utcday=SubStr(utcdate,7,2)
utcmonth=SubStr(utcdate,4,2)
utcyear=SubStr(utcdate,1,2)
decodend:
oldtime = TIME('N')
/* changed in 1.5 from DATE('B') */
olddate = DATE('I')
Date TIME tim DATE utcday'-'utcmonth'-'utcyear
/* Script to offset the time to local */
/* and calculates your localtime 'error' */
/* This section checks to see if locale.prefs exists */
IF ~(Exists('env:sys/locale.prefs'))
THEN DO
Say 'Fatal error *** Env:sys/locale.prefs does not exist ***'
Exit 10
END
/* put the info into a text file to read */
'type env:sys/locale.prefs hex >ram:locale.txt'
/* Read in the hex values for timezone from the locale.txt file */
IF ~Open(st,'ram:locale.txt', 'R')
THEN DO
Say '*** Unable to create temp file'
Exit 10
END
/* move to the point in the file where the timezone info is */
dummy = SEEK(st,1614,'B')
b = READCH(st,4)
/* get all hex characters up to the point */
/* of the where the two values are that hold the timezone */
/* convert the characters to their decimal equivalent */
tzoval = X2D(b)
gmtflag = 0
IF tzoval > 660 /* if the timeszone is > international date line */
THEN DO
tzoval = 65536 - tzoval /* reverse offset (12 hours or greater */
tzocalc = tzoval/60 /* convert to hours.decimins */
tzocalc = TRUNC(tzocalc,2) /* hours.mm format */
tzohour = TRUNC(tzocalc) /* hours */
tzomin = RIGHT(tzocalc,2) /* extract minutes */
tzomin = tzomin * .6 /* convert decimal to minutes */
tzomin = TRUNC(tzomin) /* discard decimals (seconds) */
tzohour = 24 - tzohour /* complete the offset */
if tzomin > 0 THEN tzohour = tzohour -1
gmtflag = 1
END
IF gmtflag = 0 /* if the timezone is < 12 hours fom GMT */
THEN DO
tzocalc = tzoval/60 /* convert to hours.decimins */
tzocalc = TRUNC(tzocalc,2) /* hours.mm format */
tzohour = TRUNC(tzocalc) /* hours */
tzomin = RIGHT(tzocalc,2) /* extract minutes */
tzomin = tzomin * .6 /* convert decimal to minutes */
tzomin = TRUNC(tzomin) /* discard decimals (seconds) */
END
IF dst$ = 'Y' THEN tzohour = tzohour - 1 /* read dst$ in ARGS */
tzoff$ = "-" || tzohour
IF tzohour > 12
THEN DO
tzoff = 24 - tzohour
IF tzomin > 0 THEN tzoff = tzoff -1 /* Compensate for half hour zones */
tzoff$ = "+" || tzoff
END
SAY 'Time adjusted '|| tzoff$ ||' hours and ' tzomin ' minutes from UTC.'
SAY ''
/* read current system time and extract hours and minutes */
timestring = TIME('N')
mins = SUBSTR(timestring,4,2)
hour = LEFT(timestring,2)
newmins = mins - tzomin
IF newmins < 0
THEN DO
newmins = newmins + 60 /* positive value for minutes */
tzohour = tzohour + 1 /* borrow an hour for substraction */
END
offset = tzohour /* set for Your Time Zone */
localhour = hour - offset
minusday = 0
IF localhour <0
THEN DO
localhour = localhour + 24
minusday = 1
END
newhour = localhour
/* correct for hours and minutes of one character '<10' */
IF localhour <10 THEN newhour = "0" || localhour
IF newmins < 10 THEN newmins = "0" || newmins
/* create the new time string */
newtime = newhour || ":" || newmins ||SUBSTR(timestring,6,3)
/* Correct for the date */
IF (minusday = 0) & (gmtflag = 1) THEN 'DATE TOMORROW'
IF (minusday = 1) & (gmtflag = 0) THEN 'DATE YESTERDAY'
/* ELSE leave the data as TODAY */
/* AmigaDOS DATE commands */
'DATE TIME ' || newtime
'DATE'
'SetClock SAVE'
SAY ''
/* changed in 1.5 from DATE('B') */
newdate = DATE('I')
/* Compensation for initial clock read */
/* Adjust by adding 1 second due to program exec time */
/* Average exec time was .56 seconds on A3000 25MHz */
adjustment:
adjsec = RIGHT(oldtime,2)
adjmin = SUBSTR(oldtime,4,2)
adjhour = LEFT(oldtime,2)
adjsec = adjsec + 1
IF adjsec > 59 THEN
DO
adjsec = 0
adjmin = adjmin + 1
IF adjmin > 60 THEN
DO
adjmin = 0
adjhour = adjhour + 1
IF adjhour > 23 THEN
DO
adjhour = 0
olddate = olddate + 1
END
END
END
/* ensures values are converted to integer types */
adjsec = adjsec + 0
adjmin = adjmin + 0
adjhour = adjhour + 0
adjsecstr$ = adjsec
IF adjsecstr$ = '0' THEN adjsecstr$ = '00'
IF (adjsec > 0 ) & (adjsec < 10) THEN adjsecstr$ = '0' || adjsecstr$
adjminstr$ = adjmin
IF adjminstr$ = '0' THEN adjminstr$ = '00'
IF (adjmin > 0 ) & (adjmin < 10) THEN adjminstr$ = '0' || adjminstr$
adjhourstr$ = adjhour
IF adjhourstr$ = '0' THEN adjhourstr$ = '00'
IF (adjhour > 0 ) & (adjhour < 10) THEN adjhourstr$ = '0' || adjhourstr$
oldtime = adjhourstr$||':'||adjminstr$||':'||adjsecstr$
adjustmentend:
oldtimesecs = timeseccalc(oldtime)
newtimesecs = timeseccalc(newtime)
SAY ' Previous System time was: ' oldtime
SAY ' Current System time is : ' newtime
oldsecs = (olddate * 86400) + oldtimesecs
newsecs = (newdate * 86400) + newtimesecs
secdiff = newsecs - oldsecs
secdiff = ABS(secdiff)
datediff = TRUNC(secdiff / 86400)
compsecdiff = secdiff - (datediff * 86400)
diffstr$ = timediff(compsecdiff)
/* datediff = newdate - olddate */
/* datediff = ABS(datediff) */
SAY ''
SAY ' Time difference was ' datediff ' days and 'diffstr$
SAY ''
EXIT
/* ****************** TIME CALC MODDULE ************** */
/* Function to calc timesecs */
timeseccalc: procedure
ARG timestring
SECS = RIGHT(timestring,2)
MINS = SUBSTR(timestring,4,2)
HOURS = LEFT(timestring,2)
timesecs = (HOURS * 3600) + (MINS * 60) + (SECS)
RETURN timesecs
/* Function to converts seconds into HH:MM:SS format */
timediff: procedure
ARG timenumsecs
hours = timenumsecs % 3600
hoursecs = hours * 3600
mins = (timenumsecs - (hoursecs)) % 60
minsecs = mins * 60
secs = timenumsecs - hoursecs - minsecs
hourstr$ = hours
IF (hours < 10) THEN hourstr$ = '0' || hours
minstr$ = mins
IF (mins < 10) THEN minstr$ = '0' || mins
secstr$ = secs
IF (secs < 10) THEN secstr$ = '0' || secs
timeconvstr$ = hourstr$||':'||minstr$||':'||secstr$
RETURN timeconvstr$
/* **************** E N D O F P R O G R A M ****************** */